﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

namespace eTruck.Helpers
{
    public class MessageBoxHelper
    {
        public static void MessageBox(Page page, string message, string url)
        {
            string strKey = "Alert";
            string StrScript = "";
            if (message.Length > 0)
            {
                message = message.Replace("'", "#");
                message = message.Replace("\r", "\\r").Replace("\n", "\\n").Replace("\'", "&apos;");

                StrScript = "alert('" + message + "');";
            }
            if (url.Equals("history.go(-1)"))
            {
                StrScript += "window.history.go(-1);";
            }
            else
            {
                if (url.Length > 0 && url != "#")
                {
                    StrScript += "window.location.href='" + url + "';";
                }
            }

            page.ClientScript.RegisterClientScriptBlock(page.GetType(), strKey, StrScript, true);

        }
    }
}